/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.mobbuzz.page.menu.inbox;

import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Dialog;
import com.sun.lwuit.Font;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import edu.mobbuzz.bean.Message;
import edu.mobbuzz.page.menu.Menu;
import java.util.Date;

public class MessageFormPage extends Menu {
    private Form messageForm;
    private Container messsagePanel;
    private Label menuTitle;
    private TextArea descriptionTxtArea;
    private Command backCmd;
    private Command sendCmd;
    private Message message;
    private int mode;

    public int getMode() {
        return mode;
    }

    public void setMode(int mode) {
        this.mode = mode;
    }

    public Message getMessage() {
        return message;
    }

    public void setMessage(Message message) {
        this.message = message;
    }
    
    public MessageFormPage(){
        if(getMessage()!=null){
            descriptionTxtArea.setText(getMessage().getDescription());
        }
        messageForm = new Form();
        messsagePanel = new Container();
        menuTitle = new Label(getMenuTitle());

        descriptionTxtArea = new TextArea(8, 20);


        sendCmd = new Command("Send") {
            public void actionPerformed(ActionEvent evt) {
                enterContactID();
            }
        };

        backCmd = new Command("Back") {
            public void actionPerformed(ActionEvent evt) {
                backToInboxPage();
            }
        };
    }

    public void showPage(){
        
        menuTitle.setAlignment(Component.CENTER);
        menuTitle.getStyle().setMargin(5, 0, 5, 0);
        menuTitle.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
        menuTitle.getStyle().setBgTransparency(0);

        

        descriptionTxtArea.setFocusable(true);
        descriptionTxtArea.getStyle().setMargin(2, 10, 10, 10);

        messsagePanel.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        messsagePanel.addComponent(menuTitle);
        messsagePanel.addComponent(descriptionTxtArea);

        messageForm.setLayout(new BorderLayout());
        messageForm.addComponent(BorderLayout.CENTER, messsagePanel);
        messageForm.addCommand(backCmd);
        messageForm.addCommand(sendCmd);
       

        messageForm.setCommandListener(getActionlistener());
        messageForm.show();
    }


    public void enterContactID(){
        Message msg = new Message();
        msg.setSource("");
        msg.setLink("");
        msg.setDate(new Date().toString());
        msg.setTitle("");
        msg.setDescription(descriptionTxtArea.getText());
        msg.setPubdate(new Date().toString());
        msg.setFrom(getMessaging().getUsername());

        RecepientPage contactPage = new RecepientPage();
        contactPage.setExitCmd(getExitCmd());
        contactPage.setActionlistener(getActionlistener());
        contactPage.setMessage(msg);
        contactPage.setMode(getMode());
        contactPage.showPage();
    }

    public void backToInboxPage(){
        InboxPage inboxPage = new InboxPage();
        inboxPage.setExitCmd(getExitCmd());
        inboxPage.setActionlistener(getActionlistener());
        inboxPage.showPage();
    }

    
    
    public String getMenuTitle() {
        return "New Message";
    }

    
}
